home *** CD-ROM | disk | FTP | other *** search
- //===========================================================================
- // Project : OMFEDIT
- // Module : omfedit.c
- // Purpose : edit the pilot files of Epic Megagames' One Must Fall (TM)
- // Notice : use however you like, but hold me blameless
- // Author : David Bollinger, CIS# 72510,3623
- // Created : 10/16/94
- // Revised : Paul and Jim Kenney, CIS# 72604, 3253
- // Notes : compiled with Borland C++ 3.1, small model
- //---------------------------------------------------------------------------
- //
- // IMPORTANT: REGISTER YOUR COPY OF "ONE MUST FALL" TODAY !
- //
- // BACKUP YOUR PILOT FILE BEFORE EDITING !
- //
- // EAT YOUR VEGETABLES AND FLOSS BETWEEN MEALS !
- //
- //---------------------------------------------------------------------------
- //
- // WHAT THIS PROGRAM DOES (CURRENTLY): Simply gives your pilot more money,
- // you can then do with it as you like. If you really need to cheat you
- // can run it multiple times on the same pilot file, or change the amount
- // of illicit money in the function call and recompile. Below is a
- // rough list of some other data values - experiment at your own risk.
- // If you come up with something, though, it would be cool to share it!
- //
- // Description of Pilot Files (*.CHR):
- //
- // Encoding method: Cyclical key XOR (initial key value 0xAC)
- //
- // PILOT DATA INTERPRETATION: (very tentative)
- // (obviously, it would be nice to wrap this into a structure)
- //
- // Decimal Interpret
- // Offset Type Meaning Confidence
- // ------- ---- ----------------------------------------- ----------
- // 000-003 always zero?
- // 004-019 byte name high+
- // 022-023 int wins high+
- // 024-025 int losses high+
- // 026 byte rank high
- // 028 -+ arm power/leg power low
- // 029 |bit leg power/arm speed low
- // 030 |pack leg speed/armor low
- // 031 -+ stun resitance low
- // 040-043 long money (in K$) high+
- // 044 byte second body color high
- // 045 byte third body color high
- // 046 byte main body color high
- // 047-059 byte tournament filename high
- // 060-090 byte tournament description med
- // 091-103 byte tournament picture filename high
- // 260-262 changes when arm/leg speed/power changes? low-
- //
- // 263-1399 god only knows (encoded)
- // 1400-1559 elam only knows (not encoded)
- //
- // 1560(?)-EOF pilot picture bitmap, format unknown low-
- //---------------------------------------------------------------------------
- //
- // Limitations:
- // The count of 1400 encoded bytes is PROBABLY right, but...
- // Fortunately, due to XOR encoding, we can decode/encode a few too many/
- // too few bytes and everything else still works.
- //
- // The bitmap does not APPEAR to be encoded, just a wacky format.
- //
- // Hint (for what it's worth): the bitmap format MAY be a series of 3
- // ints (maybe offsets and counts) followed by the actual pixel data
- // for each line, variable width lines. If you want to make your own
- // bitmaps you'll need to figure this out.
- //
- // This is left as an exercise for the reader, there will be a test at
- // the end of the semester :)
- //---------------------------------------------------------------------------
-
- //===========
- // directives
- //-----------
-
- //=========
- // includes
- //---------
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <io.h>
- #include <fcntl.h>
- #include <sys\types.h>
- #include <ctype.h>
- #include <sys\stat.h>
-
-
- //========
- // defines
- //--------
-
- #define CODED_SIZE 1400 // # of coded bytes, roughly
-
- //===================
- // typedefs & structs
- //-------------------
- typedef unsigned char uchar;
- typedef unsigned int uint;
- typedef struct omf {
- long zero;
- char name[15];
- char none1[2];
- int wins;
- int losses;
- int rank:8;
- char none2;
- char arm_power;
- char leg_power;
- char leg_speed;
- int stun_resistance:8;
- char none3[6];
- long money;
- int body_color2:8;
- int body_color3:8;
- int body_main:8;
- char tourn_file[12];
- char tourn_desc[30];
- char tourn_pic[12];
- char none4[157];
- int arm_leg;
- char filler[1136];
- char filler2[159];
- } omfr;
-
-
- //===========
- // prototypes
- //-----------
- void EnDeCode(omfr *);
- long strtolong(char *);
-
- //========
- // globals
- //--------
- char pilotfile[13];
-
- //============================================================================
- main(int argc, char *argv[])
- {
-
- char input[40];
- char sel[2];
- int in;
- int filesize;
- char *ptr;
- omfr *omfrec;
- struct stat statbuf;
-
- if (argc < 2)
- {
- printf("\nInput Pilotfile Name. ");
- gets(pilotfile);
- }
- else
- strncpy(pilotfile, argv[1], 12);
-
- in = open(pilotfile,O_RDWR | S_IREAD | S_IWRITE | O_BINARY);
- if (in == -1)
- {
- printf("\nFile not found");
- return 0;
- }
-
- stat(pilotfile,&statbuf);
- filesize = statbuf.st_size;
- omfrec = malloc((int) filesize);
-
- read(in,omfrec,filesize);
-
- EnDeCode(omfrec);
- do
- {
- printf("\n Name is : %s",omfrec->name);
- printf("\n");
- printf("\n1 Change wins Currently : %i",omfrec->wins);
- printf("\n2 Change losses Currently : %i",omfrec->losses);
- printf("\n3 Change rank Currently : %d",omfrec->rank);
- printf("\n*4 Change arm-leg power Currently : %d",omfrec->arm_power);
- printf("\n*5 Change arm-leg speed Currently : %d",omfrec->leg_power);
- printf("\n*6 Change stun res. Currently : %d",omfrec->stun_resistance);
- printf("\n7 Change money Currently : %ld",omfrec->money);
- printf("\nQ Quit + save");
- printf("\nX Quit");
- printf("\n\nAn * means USE AT YOUR OWN RISK. UNKNOWN EFFECT.");
- printf("\nEnter selection please. ");
-
- gets(sel);
- strupr(sel);
-
- switch (sel[0])
- {
- case '1':
- printf("\nEnter the new number for wins. ");
- gets (input);
- omfrec->wins = strtolong(input);
- break;
-
- case '2':
- printf("\nEnter the new number for losses. ");
- gets (input);
- omfrec->losses = strtolong(input);
- break;
-
- case '3':
- printf("\nEnter the new number for rank. ");
- gets(input);
- omfrec->rank = strtolong(input);
- break;
-
- case '4':
- printf("\nEnter new arm-leg power. ");
- gets(input);
- omfrec->arm_power = strtolong(input);
- break;
-
- case '5':
- printf("\nEnter new arm-leg speed. ");
- gets(input);
- omfrec->leg_power = strtolong(input);
- break;
-
-
- case '6':
- printf("\nEnter new stun res. ");
- gets(input);
- omfrec->stun_resistance = strtolong(input);
- break;
-
- case '7':
- printf("\nEnter new amount of money. ");
- gets(input);
- omfrec->money = strtolong(input);
- break;
-
- case 'Q':
- EnDeCode(omfrec);
- lseek(in,0L,SEEK_SET);
- write(in,omfrec,filesize);
- break;
-
- case 'X':
- break;
- }
-
- } while (sel[0] != 'X' && sel[0] != 'Q');
-
-
- close(in);
-
- free(omfrec);
- return 0;
- }
-
- long strtolong(char *input)
- {
- long work;
- sscanf(input,"%ld",&work);
- return(work);
- }
-
- //============================================================================
- // XOR coding is reflexive, can use same routine for encode/decode
- //----------------------------------------------------------------------------
- void EnDeCode(omfr *omfrec)
- {
- register int i;
- uchar *pptr=(char *) omfrec;
- uchar key=0xac;
-
- for (i=CODED_SIZE; i>=0; i--)
- *pptr++ ^= key++;
- }
-